﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Perform
{
    public partial class FrmRigister : Form
    {
        public FrmRigister()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void btn_rigister_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void btnYes_Click(object sender, EventArgs e)
        {
            string username = txtUserName.Text.Trim();
            string password = txtPsw.Text.Trim();
            string confirm = txtComfirm.Text.Trim();
            string sql1 = string.Format("select count(1) from[User] where uName = '{0}'",username);
            string sql2 = string.Format("insert into [User] (uName,uPassword) values ('{0}','{1}')", username, password);
            int result = Dal.DataHelper.sqlExecuteScalar(sql1);
            if(password != confirm)
            {
                MessageBox.Show("两次输入的密码不同，请重新输入！");
                txtUserName.Clear();
                txtPsw.Clear();
                txtComfirm.Clear();
            }
            else if(result == 1)
            {
                MessageBox.Show("该账户名已经被注册，请重新注册！");
                txtUserName.Clear();
                txtPsw.Clear();
                txtComfirm.Clear();
            }
            else if(username == "" || password == "")
            {
                MessageBox.Show("请输入正确的账户名及密码！");

            }
            else
            {
                int re = Dal.DataHelper.sqlExecuteNonQuery(sql2);
                MessageBox.Show("注册成功！请前往登陆");
                this.Hide();
            }
        }
    }
}
